import axios from 'axios'
import store from '@/store'

// 基地址
// const baseURL = 'http://192.168.31.82:3000'
const baseURL = 'http://192.168.31.140:3001/'
// >>>>>>> cb8a475a2651632fb523402bb8289120292f67af

// 创建axios实例
const request = axios.create({
  baseURL,
  timeout: 5000
})

// 请求拦截器
request.interceptors.request.use(config => {
  const token = store.state.user.token
  if (token) {
    config.headers.Authorization = `Bearer ${token}`
  }
  return config
}, err => {
  return Promise.reject(err)
})

// 响应拦截器
request.interceptors.response.use(response => response.data, err => {
  return Promise.reject(err)
})

export default (url, method, submitData) => {
  return request({
    url,
    method,
    [method.toLowerCase === 'get' ? 'params' : 'data']: submitData
  })
}
